-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse month from string in customParseFormat #457
Conversation
@@ -64,15 +64,16 @@ const parseDate = (date) => { | |||
|
|||
class Dayjs { | |||
constructor(cfg) { | |||
this.$L = this.$L || parseLocale(cfg.locale, null, true) || L |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make locale available in parse() function
Codecov Report
@@ Coverage Diff @@
## dev #457 +/- ##
===================================
Coverage 100% 100%
===================================
Files 55 58 +3
Lines 484 525 +41
Branches 75 88 +13
===================================
+ Hits 484 525 +41
Continue to review full report at Codecov.
|
@iamkun Is it ok now? |
I'll test |
|
MM: [match2, addInput('month')], | ||
MMM: [matchWord, function (input) { | ||
const locale = instance.$locale() | ||
const { months } = locale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also consider monthsShort
in some locales
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change locale before date parsing
?
? monthsShort.findIndex(month => month === input) | ||
: months.findIndex(month => month.substr(0, 3) === input) | ||
if (matchIndex < 0) { | ||
throw new Error(`Failed to parse "${input}" as MMM`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no error, just skip it like others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But suddenly it broke the tests on "Invalid Date" after parse corrupted string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, am I should to bring errors back?
const inputUk = '2018 трав 03' | ||
const format = 'YYYY MMM DD' | ||
dayjs.locale(uk) | ||
expect(dayjs(inputUk, format).valueOf()).toBe(moment(input, format).valueOf()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a good test .
we should compare with
moment.locale('uk')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
I also write test with passing locale in config (btw, it is undocumented for now)
}) | ||
|
||
it('return Invalid Date when parse corrupt string', () => { | ||
const input = '2018 Februaru 03' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why moment('2018 Februaru 03', 'YYYY MMMM DD')
returns a valid date.
But we might should change Februaru
to another error string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@iamkun Take a look, please! |
## [1.8.7](v1.8.6...v1.8.7) (2019-02-24) ### Bug Fixes * Add plugin type definitions ([#418](#418)) ([361d437](361d437)) * Add Swahili locale ([#508](#508)) ([b9cee84](b9cee84)) * Parse month string 'MMMM MMM (February, Feb)' in customParseFormat ([#457](#457)) ([f343206](f343206)) * Update declaration file .diff .isBefore .isSame .isAfter ([#496](#496)) ([4523275](4523275)) * Word orders corrections for locale 'fa' ([#491](#491)) ([56050c2](56050c2))
🎉 This PR is included in version 1.8.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [1.8.7](iamkun/dayjs@v1.8.6...v1.8.7) (2019-02-24) ### Bug Fixes * Add plugin type definitions ([#418](iamkun/dayjs#418)) ([361d437](iamkun/dayjs@361d437)) * Add Swahili locale ([#508](iamkun/dayjs#508)) ([b9cee84](iamkun/dayjs@b9cee84)) * Parse month string 'MMMM MMM (February, Feb)' in customParseFormat ([#457](iamkun/dayjs#457)) ([f343206](iamkun/dayjs@f343206)) * Update declaration file .diff .isBefore .isSame .isAfter ([#496](iamkun/dayjs#496)) ([4523275](iamkun/dayjs@4523275)) * Word orders corrections for locale 'fa' ([#491](iamkun/dayjs#491)) ([56050c2](iamkun/dayjs@56050c2))
## [1.8.7](iamkun/dayjs@v1.8.6...v1.8.7) (2019-02-24) ### Bug Fixes * Add plugin type definitions ([#418](iamkun/dayjs#418)) ([361d437](iamkun/dayjs@361d437)) * Add Swahili locale ([#508](iamkun/dayjs#508)) ([b9cee84](iamkun/dayjs@b9cee84)) * Parse month string 'MMMM MMM (February, Feb)' in customParseFormat ([#457](iamkun/dayjs#457)) ([f343206](iamkun/dayjs@f343206)) * Update declaration file .diff .isBefore .isSame .isAfter ([#496](iamkun/dayjs#496)) ([4523275](iamkun/dayjs@4523275)) * Word orders corrections for locale 'fa' ([#491](iamkun/dayjs#491)) ([56050c2](iamkun/dayjs@56050c2))
## [1.8.7](iamkun/dayjs@v1.8.6...v1.8.7) (2019-02-24) ### Bug Fixes * Add plugin type definitions ([#418](iamkun/dayjs#418)) ([361d437](iamkun/dayjs@361d437)) * Add Swahili locale ([#508](iamkun/dayjs#508)) ([b9cee84](iamkun/dayjs@b9cee84)) * Parse month string 'MMMM MMM (February, Feb)' in customParseFormat ([#457](iamkun/dayjs#457)) ([f343206](iamkun/dayjs@f343206)) * Update declaration file .diff .isBefore .isSame .isAfter ([#496](iamkun/dayjs#496)) ([4523275](iamkun/dayjs@4523275)) * Word orders corrections for locale 'fa' ([#491](iamkun/dayjs#491)) ([56050c2](iamkun/dayjs@56050c2))
to handle 'MMM' and 'MMMM' formats (February, Feb, etc)